<?php

class PublicController extends Controller
{
//	public function actionIndex()
//	{
//        echo 1;
//	}

    public function actionLogin()
    {
        if (!Yii::app()->user->isGuest)
            $this->redirect(array('default/index'));
        else
        {
            // 把model获取
            $model = new LoginForm();

            if (isset($_POST['LoginForm'])) {
                $model->attributes = $_POST['LoginForm'];
                if ($model->validate() && $model->login()) {
                    $this->redirect(array('default/index'));
                }
            }

            $this->render('login', array('model' => $model));
        }
    }

    // 成功显示
    public function actionSuccess($msg, $url='')
    {
        $this->render('success', array('msg'=>urlencode($msg), 'url'=>urlencode($url)));
    }

    // 退出
    public function actionLogout()
    {
        if(!Yii::app()->user->isGuest)
        {
            Yii::app()->user->logout();
            $this->redirect(array('public/login'));
        }
    }
}